<?php
/**
 * Created by PhpStorm.
 * User: tjjs
 * Date: 17-8-10
 * Time: 上午11:02
 */

namespace Actions;

use Data\Food_DAO;
use Data\Order_for_foods_DAO;
use Data\Order_form_DAO;
use Utils\SysUtils;

class RestaurantPrintHand extends BaseAction
{
    public function doAction() {
        parent::doAction();
        // 订单id
        $order_form_id = $this->data[ORDER_FORM_ID];
        $order_form_record = Order_form_DAO::getRecord($order_form_id);
        if (!$order_form_record) {
            return $this->SendErrMsg("错误，没有此订单信息");
        }
        // 商家id
        $restaurant_id = $order_form_record->getRESTAURANT_ID();
        // 订单中商品信息
        $order_for_food_list = Order_for_foods_DAO::getListByOrderFormId($order_form_id);
        foreach ($order_for_food_list as $key=>$order_for_food_record) {
            $food_id = $order_for_food_record[FOOD_ID];
            $food_name = Food_DAO::getName($food_id);
            $order_for_food_list[$key][FOOD_NAME] = $food_name;
        }
        // 订单全部信息
        $order_info[ORDER_FORM_INFO] = $order_form_record->getArray();
        $order_info[ORDER_FORM_INFO][ORDER_FOR_FOOD_INFO] = $order_for_food_list;
        $sendData = $order_info;


        // 推送
        $restaurant_id=1;
        SysUtils::notifyTofFrontEnd($restaurant_id,$sendData,EVENT_RESTAURANT_NEW_ORDER);

        $this->ResponseDataToCurrentClient();
    }
}